<?php

namespace App\Admin\Controllers\Configs;

use App\Admin\Repositories\SystemConfig;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

use Dcat\Admin\Widgets\Alert;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Layout\Row;
use Dcat\Admin\Layout\Column;
use App\Services\ConfigService;

class deductConfigController extends AdminController
{
    public function edit($id,Content $content)
    {
        $alert = Alert::make( "【10 表示 10 单扣一单】此处为初始默认设置，在代理账号可单独设置",'提示');
        $config = ConfigService::deductConfig();
        return $content
            ->header('扣量设置')
            ->body(
            function (Row $row) use($alert,$config){
                $row->column(6, function (Column $column) use($alert,$config) {
                    $column->row($alert->danger());
                    $column->row($this->form()->edit($config['id']));
                });
            });
    }
    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $conf = ConfigService::deductConfig();
        return Form::make($conf, function (Form $form) use ($conf) {
            // $form->display('id');
            $form->hidden('name');
            $form->hidden('slug');
            $form->embeds('content', '', function ($form) use ($conf) {
                $form->decimal('deduct', '扣量')->type('number')->attribute('min', 0)->attribute('max', 10000)->default($conf['content']['deduct'])->help('数字 10 表示 10 单扣一单');
            });
            $form->hidden('mark');
        
            
            $form->disableHeader();
            $form->footer(function ($footer) {

                // 去掉`查看`checkbox
                $footer->disableViewCheck();
            
                // 去掉`继续编辑`checkbox
                $footer->disableEditingCheck();
            
                // 去掉`继续创建`checkbox
                $footer->disableCreatingCheck();
            });
            $form->saved(function (Form $form) {
                cache()->forget('system_deduct');
                return $form->response()->success('保存成功')->redirect("system-deduct/1/edit");
            });
        });
    }
}
